package com.sample.generator.demo.provider;

import org.apache.struts.config.FormBeanConfig;
import org.apache.struts.config.FormPropertyConfig;
import org.apache.struts.config.ModuleConfig;
import org.apache.struts.config.impl.ModuleConfigImpl;

import com.sample.generator.config.impl.FileWriterConfig;
import com.sample.generator.context.GenerationContext;
import com.sample.generator.context.GenerationContextProvider;
import com.sample.generator.context.impl.DefaultGeneratorContext;

public class StrutsConfigContextProvider implements GenerationContextProvider {

	public GenerationContext[] provideContexts() {

		GenerationContext context = new DefaultGeneratorContext();

		context.addWriterConfig(new FileWriterConfig("struts-config.xml",
				"UTF-8"));

		FormPropertyConfig formPropertyConfig = new FormPropertyConfig();
		formPropertyConfig.setName("example");
		formPropertyConfig.setInitial("EXAMPLE");

		FormBeanConfig formBeanConfig = new FormBeanConfig();
		formBeanConfig.setName("example");
		formBeanConfig
				.setType("org.apache.struts.webapp.examples.CustomFormBean");
		formBeanConfig.addFormPropertyConfig(formPropertyConfig);

		ModuleConfig moduleConfig = new ModuleConfigImpl();
		moduleConfig
				.setActionFormBeanClass("org.apache.struts.webapp.examples.CustomFormBean");
		moduleConfig.addFormBeanConfig(formBeanConfig);
		moduleConfig.addFormBeanConfig(formBeanConfig);

		return new GenerationContext[] { context };
	}
}
